import requests
import pandas as pd
crisp_key = "d3db9101f93fc24ecd64266e51e08f39"

# 地理编码
def geocode(key,address):
    geocode_url = "https://restapi.amap.com/v3/geocode/geo?parameters"
    params = {
    "key":key,
    "address":address
}
    r = requests.get(geocode_url,params)
    results = r.json()['geocodes'][0]['location']
    return results

# 逆地理编码
def regeo(key,location,extensions="base",radius=None,poitype=None,roadlevel=None):
    regeo_url = "https://restapi.amap.com/v3/geocode/regeo?parameters"
    params = {
        "key":key,
        "location":location,
        "extensions":extensions,
        "radius":radius,
        "poitype":poitype,
        "roadlevel":roadlevel,
    }
    r = requests.get(regeo_url,params)
    results = r.json()['regeocode']['formatted_address']
    return results

# 步行路径规划
def walk(key,origin,destination):
    walk_url = "https://restapi.amap.com/v3/direction/walking?parameters"
    params = {
        "key":key,
        "origin":origin,
        "destination":destination
    }
    r = requests.get(walk_url,params)
    results = r.json()['route']['paths'][0]['steps']
    return results

# 公交路径规划
def bus(key,origin,destination,city):
    bus_url = "https://restapi.amap.com/v3/direction/transit/integrated?parameters"
    params = {
        "key":key,
        "origin":origin,
        "destination":destination,
        "city":city
    }
    r = requests.get(bus_url,params)
    results = r.json()
    return results

# 驾车路径规划
def car(key,origin,destination):
    car_url = "https://restapi.amap.com/v3/direction/driving?parameters"
    params = {
        "key":key,
        "origin":origin,
        "destination":destination
    }
    r = requests.get(car_url,params)
    results = r.json()
    return results

# 骑行路径规划
def bicycle(key,origin,destination):
    bicycle_url = "https://restapi.amap.com/v4/direction/bicycling?parameters"
    params = {
        "key":key,
        "origin":origin,
        "destination":destination
    }
    r = requests.get(bicycle_url,params)
    results = r.json()['data']['paths'][0]['steps']
    return results

# 距离测量
def distance(key,origins,destination):
    distance_url = "https://restapi.amap.com/v3/distance?parameters"
    params = {
        "key":key,
        "origins":origins,
        "destination":destination
    }
    r = requests.get(distance_url,params)
    distance = r.json()['results'][0]['distance']
    return distance

# 行政区域查询
def administrative_region(key,keywords):
    administrative_region_url = "https://restapi.amap.com/v3/config/district?parameters"
    params = {
        "key":key,
        "keywords":keywords
    }
    r = requests.get(administrative_region_url,params)
    administrative_region = r.json()['districts'][0]['districts']
    return administrative_region

# 关键字搜索
def keywords(key,keywords):
    keywords_url = "https://restapi.amap.com/v3/place/text?parameters"
    params = {
        "key":key,
        "keywords":keywords
    }
    r = requests.get(keywords_url,params)
    search = r.json()
    return search

# 周边搜索
def circum(key,location):
    circum_url = "https://restapi.amap.com/v3/place/around?parameters"
    params = {
        "key":key,
        "location":location
    }
    r = requests.get(circum_url,params)
    circum = r.json()
    return circum

# 多边形搜索
def polygon(key,polygon):
    polygon_url = "https://restapi.amap.com/v3/place/polygon?parameters"
    params = {
        "key":key,
        "polygon":polygon
    }
    r = requests.get(polygon_url,params)
    polygon = r.json()['pois']
    return polygon

# ID查询
def ID(key,id):
    ID_url = "https://restapi.amap.com/v3/place/detail?parameters"
    params = {
        "key":key,
        "id":id
    }
    r = requests.get(ID_url,params)
    ID = r.json()
    return ID

# IP定位
def IP(key):
    IP_url = "https://restapi.amap.com/v3/ip?parameters"
    params = {
        "key":key
    }
    r = requests.get(IP_url,params)
    IP = r.json()
    return IP

# 静态地图
def static(key,location,zoom,size):
    static_url = "https://restapi.amap.com/v3/staticmap?parameters"
    params = {
        "key":key,
        "location":location,
        "zoom":zoom,
        "size":size
    }
    r = requests.get(static_url,params)
    static = r.url
    return static

# 坐标转换
def coordinates(key,locations):
    coordinates_url = "https://restapi.amap.com/v3/assistant/coordinate/convert?parameters"
    params = {
        "key":key,
        "locations":locations,
    }
    r = requests.get(coordinates_url,params)
    coordinates = r.json()['locations']
    return coordinates

# 天气查询
def weather(key,city):
    weather_url = "https://restapi.amap.com/v3/weather/weatherInfo?parameters"
    params = {
        "key":key,
        "city":city,
        "extensions":"all"
    }
    r = requests.get(weather_url,params)
    weather = r.json()
    return weather

# 输入提示
def input(key,keywords):
    input_url = "https://restapi.amap.com/v3/assistant/inputtips?parameters"
    params = {
        "key":key,
        "keywords":keywords
    }
    r = requests.get(input_url,params)
    input = r.json()
    return input